package org.paraj.misc;

import java.util.Iterator;

public class SynchronizedIterator<T> implements Iterator<T>{
    Iterator<T> iterator;

    public SynchronizedIterator(Iterator<T> iterator){
        this.iterator = iterator;
    }

    public synchronized boolean hasNext(){
        return iterator.hasNext();
    }

    public synchronized T next(){
        return iterator.next();
    }

    public synchronized void remove(){
        iterator.remove();
    }

    public synchronized T nextOrNull(){
        return iterator.hasNext() ? iterator.next() : null;
    }
}